//
//  RoomDetailViewController.m
//  LiveEducation
//
//  Created by Liu,Qingcan on 2017/4/19.
//  Copyright © 2017年 Baidu. All rights reserved.
//

#import "RoomDetailViewController.h"
#import "RoundViewController.h"
#import "RoundInfoViewController.h"
#import "YYWebImage.h"

#define NavBarH 64
@interface RoomDetailViewController ()

@property (nonatomic,strong)UIImageView *imageView;


@end

@implementation RoomDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setDatas];
    [self addSubviews];
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:YES];
    
    self.tabBarController.tabBar.hidden = YES;
}



//- (void)viewWillLayoutSubviews{
//
//}

#pragma private
- (void)addSubviews{
    self.view.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.imageView];
    [self setSegTitleView];
    [self setupSegView];
    [self.segView showVCWithIndex:0 outsideVC:self];
}

- (void)setDatas{
    self.titleArray = [[NSMutableArray alloc]initWithObjects:@"目录",@"课程介绍",nil];
    CGRect subviewFrame = CGRectMake(0, 0, self.view.frame.size.width, [UIScreen mainScreen].bounds.size.height  - NavBarHeight - 40 - self.imageView.frame.size.height);

    RoundViewController *roundVC = [RoundViewController initWithSubframe:subviewFrame roomId:self.roomItem.nid];
    [self.vcArray addObject:roundVC];
    [self addChildViewController:roundVC];
    
    RoundInfoViewController *infoVC = [RoundInfoViewController initWithSubframe:subviewFrame roomItem:self.roomItem];
    [self.vcArray addObject:infoVC];
    [self addChildViewController:infoVC];
    
}

- (void)setSegTitleView{
    self.segTitleView = [WLSegmentTitleView initWithFrame:CGRectMake(0, self.imageView.frame.size.height + NavBarHeight, self.view.frame.size.width, 40) delegate:self childTitles:self.titleArray isScaleTitleText:YES isScroll:NO];
    self.segTitleView.backgroundColor = [UIColor whiteColor];
    self.segTitleView.titleSelectColor = [UIColor colorWithRed:172/255.f green:199/255.f blue:166/255.f alpha:1];
    self.segTitleView.titleColor = [UIColor blackColor];
    //[UIColor colorWithRed:85/255.f green:210/255.f blue:208/255.f alpha:1];
    self.segTitleView.segmentStyle = WLSegmentTitleStyleBottomIndicatorLine;
    self.segTitleView.indicatorColor = [UIColor colorWithRed:172/255.f green:199/255.f blue:166/255.f alpha:1];
//    self.segTitleView.segmentBackImage = [UIImage imageNamed:@"bantouming3"];
//    self.segTitleView.backgroundColor = [UIColor colorWithRed:127/255.f green:127/255.f blue:127/255.f alpha:0.5];//44 42 47
    
    self.segTitleView.titleFontGradualChange = YES;
    [self.view addSubview:self.segTitleView];
    
}

- (void)setupSegView{
    self.segView = [WLSegmentView segmentViewWithFrame:CGRectMake(0, NavBarHeight + self.segTitleView.frame.size.height+self.imageView.frame.size.height, self.view.frame.size.width, self.view.frame.size.height - (NavBarHeight + self.segTitleView.frame.size.height + self.imageView.frame.size.height))];
    self.segView.vcArray = self.vcArray;
    self.segView.delegate = self;
    [self.view addSubview:self.segView];
}





#pragma getter

- (UIImageView *)imageView{
    if (!_imageView) {
        _imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, NavBarH, [UIScreen mainScreen].bounds.size.width, 150)];
        _imageView.contentMode = UIViewContentModeScaleAspectFill;
        _imageView.backgroundColor = [UIColor cyanColor];
    }
    return _imageView;
}

#pragma mask setter

- (void)setRoomItem:(LERoomItem *)roomItem{
    if (!roomItem) {
        return;
    }
    _roomItem = roomItem;
    [self.imageView yy_setImageWithURL:[NSURL URLWithString:roomItem.image] placeholder:[UIImage imageNamed:@"backImage"]];
    
//    [self.imageView setImage:[UIImage imageNamed:roomItem.image]];
    
    
}
@end
